home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
math
/
nrpas13
/
spline.dem
< prev
next >
Wrap
Text File
|
1991-04-29
|
769b
|
34 lines
PROGRAM d3r3 (input,output);
(* driver for routine SPLINE *)
CONST
n=20;
pi=3.1415926;
TYPE
glnarray = ARRAY [1..n] OF real;
VAR
i : integer;
yp1,ypn : real;
x,y,y2 : glnarray;
(*$I MODFILE.PAS *)
(*$I SPLINE.PAS *)
BEGIN
writeln ('second-derivatives for sin(x) from 0 to pi');
(* generate array for interpolation *)
FOR i := 1 to 20 DO BEGIN
x[i] := i*pi/n;
y[i] := sin(x[i])
END;
(* calculate 2nd derivative with spline *)
yp1 := cos(x[1]);
ypn := cos(x[n]);
spline(x,y,n,yp1,ypn,y2);
(* test result *)
writeln ('spline':23,'actual':16);
writeln ('number':11,'2nd deriv':14,'2nd deriv':16);
FOR i := 1 to n DO BEGIN
writeln (i:8,y2[i]:16:6,-sin(x[i]):16:6)
END
END.